package servlet;

import webapi.MyHttpServletRequest;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;

/*
 * servlet api的装饰类
 * 实现原生接口的servlet
 */
@WebServlet(urlPatterns = "/hello")
public class HelloServlet implements Servlet {
    /**
     * servlet配置信息
     * 获取servletContext对象
     */
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        // servlet引擎为每一个web应用都创建了一个servletContext
        // 可以获取当前web应用的各方面信息
        // 代表当前web应用
        // application对象
        ServletContext servletContext = servletConfig.getServletContext();
        //web的启动参数
        String parameter = servletContext.getInitParameter("namespace");
        //一个文件在服务器上的绝对路径
        String realPath = servletContext.getRealPath("/");
        //获取web应用的名称
        String contextPath = servletContext.getContextPath();
        //获取web应用下某一文件的输入流
        InputStream inputStream = servletContext.getResourceAsStream("");
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        MyHttpServletRequest request = new MyHttpServletRequest(httpServletRequest);

    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}




